home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 4: GNU Archives / Linux Cubed Series 4 - GNU Archives.iso / gnu / fontutil.6 / fontutil / fontutils-0.6 / lib / line.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-05-19  |  1.4 KB  |  51 lines

  1. /* line.c: read an arbitrary-length line from a file, returning the result
  2.    as a string.
  3.  
  4. Copyright (C) 1992 Free Software Foundation, Inc.
  5.  
  6. This program is free software; you can redistribute it and/or modify
  7. it under the terms of the GNU General Public License as published by
  8. the Free Software Foundation; either version 2, or (at your option)
  9. any later version.
  10.  
  11. This program is distributed in the hope that it will be useful,
  12. but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14. GNU General Public License for more details.
  15.  
  16. You should have received a copy of the GNU General Public License
  17. along with this program; if not, write to the Free Software
  18. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.  */
  19.  
  20. #include "config.h"
  21.  
  22. #include "line.h"
  23. #include "varstring.h"
  24.  
  25.  
  26. /* Return the next line of IN_FILE, or NULL if we are at EOF.  The
  27.    string is allocated with malloc.  */
  28.  
  29. string
  30. read_line (FILE *in_file)
  31. {
  32.   int c;
  33.   variable_string answer = vs_init ();
  34.  
  35.   /* Have to check for EOF before appending the character.  */
  36.   while ((c = getc (in_file)) != EOF && c != '\n')
  37.     {
  38.       vs_append_char (&answer, c);
  39.     }
  40.   
  41.   /* Append the null (assuming here that null characters don't appear in
  42.      the text files), if we found any characters.  */
  43.   if (c != EOF)
  44.     {
  45.       vs_append_char (&answer, 0);
  46.       return VS_CHARS (answer);
  47.     }
  48.   else
  49.     return NULL;
  50. }
  51.